import {Injectable} from '@angular/core';
import {HttpUtilService} from "../../../../../services/http/http-util.service";
import {BarnUser} from "../entity/barn-user";
import {Observable} from "rxjs";
import {ResponseEntity} from "../../../../../services/http/response-entity";

@Injectable({
  providedIn: 'root'
})
export class UserInfoService {

  constructor(private http: HttpUtilService) {
  }

  /**
   * 查询用户数据
   * @param user 查询条件
   * @param current 当前页
   * @param pageSize 页面大小
   */
  queryUser(user: BarnUser, current = 0, pageSize = 0): Observable<ResponseEntity<BarnUser[]>> {
    return this.http.postPage("system/user/query", user, current, pageSize, true)
  }

  /**
   * 保存用户数据
   * @param user user
   * @param handleError
   */
  save(user: BarnUser, handleError = false): Observable<BarnUser> {
    return this.http.post<BarnUser>("system/user/save", user, handleError)
  }

  /**
   * 主键查询
   * @param id
   * @param handleError
   */
  getById(id: string, handleError = true): Observable<BarnUser> {
    return this.http.get<BarnUser>("system/user/getById/" + id, handleError)
  }
}
